from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from apps.users.models import User


class LikeCount(models.Model):
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey('content_type', 'object_id')

    liked_num = models.IntegerField(default=0)
    class Meta:
        verbose_name = '点赞数目记录'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '%s - %s - %s' % (self.content_type,self.object_id, self.liked_num)

class LikeRecord(models.Model):
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = GenericForeignKey('content_type', 'object_id')

    user = models.ForeignKey(User, on_delete=models.CASCADE)
    liked_time = models.DateTimeField(auto_now_add=True)
    class Meta:
        verbose_name = '点赞详情记录'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '%s - %s - %s' % (self.content_type,self.object_id, self.user)

from django.db import models

# Create your models here.
